import 'package:base_flutter/base_flutter.dart';
import 'package:flustars_flutter3/flustars_flutter3.dart';
import 'package:flutter/material.dart';
import 'package:ls_work/common/common.dart';
import 'package:ls_work/net/HttpUtil.dart';
import 'package:ls_work/net/net.dart';
import 'package:ls_work/res/colors.dart';
import 'package:ls_work/res/styles.dart';
import 'package:ls_work/util/toast.dart';
import 'dart:convert';
import 'package:dio/dio.dart';

import '../../util/flat_button.dart';



class MeFeedBack extends StatefulWidget {
  @override
  _MeFeedBackState createState() => _MeFeedBackState();

  final String? userId;
  MeFeedBack({
    Key? key,
    this.userId,
  }) : super(key: key);
}

class _MeFeedBackState extends State<MeFeedBack> {
  TextEditingController textFieldEditer = TextEditingController();

  int humanId = 0;

  @override
  void initState() {
    super.initState();
    humanId = SpUtil.getInt(Constant.humanId)??0;
  }

  ///提交
  _send() {
    if (textFieldEditer.text.isEmpty) {
      Toast.show('请输入反馈内容');
      return;
    }
    var map = {
      'content': textFieldEditer.text,
      'humanId': humanId,
      'source': 1
    };

    HttpUtil.instance
        .getDio()
        .post('${HttpApi.feedBack}?${requestParams(map)}')
        .then((r) {
      ///
      if (r.statusCode == 200) {
        Map<String, dynamic> map = json.decode(r.toString());
        if (map["code"].toString() == "0") {
          Toast.show('反馈成功');
          Navigator.pop(context);
        } else {
          Toast.show(map["msg"].toString());
        }
      } else {
        Toast.show(r.statusCode.toString());
      }
    }).catchError((e) {
      print(e.toString());
      Toast.show(getErrorMessage(e));
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text('意见反馈'),
          elevation: 0.5,
        ),
        body: SingleChildScrollView(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Container(
                padding: EdgeInsets.all(20),
                color: Colors.white,
                alignment: Alignment.topLeft,
                height: 200,
                // width: Screen.width,
                child: TextField(
                  controller: textFieldEditer,
                  maxLines: 10,
                  maxLength: 300,
                  autofocus: false,
                  decoration: InputDecoration(
                    hintText: "请输入意见内容",
                    hintMaxLines: 20,
                    fillColor: Colours.bg_color,
                    filled: true,
                    border: InputBorder.none,
                  ),
                ),
              ),
              Padding(
                padding: EdgeInsets.only(left: 20),
                child: Text(
                  '您的意见是我们保持进步的动力，谢谢~',
                  style: TextStyles.textGray12,
                ),
              ),
              SizedBox(
                height: 30,
              ),
              Container(
                padding: EdgeInsets.only(left: 20, right: 20),
                height: 50,
                width: double.infinity,
                child: FlatsButton(
                  child: Text("提交反馈",
                      style: TextStyle(fontSize: 18, color: Colors.white)),
                  color: Colours.app_main,
                  onPressed: _send,
                ),
              ),
            ],
          ),
        ));
  }
}
